//
//  UIScrollView+WSJRefresh.m
//  YALRentalPullToRefresh
//
//  Created by macOS on 2017/3/5.
//  Copyright © 2017年 Konstantin Safronov. All rights reserved.
//

#import "UIScrollView+WSJRefresh.h"
#import <objc/runtime.h>



@implementation UIScrollView (WSJRefresh)




- (void)wsj_addHeaderRefreshBlock:(RefreshBlock)refresh{
    
   YALSunnyRefreshControl *f = [YALSunnyRefreshControl new];
    
    objc_setAssociatedObject(self, "YALSunnyRefreshControl", f, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    if (refresh) {
        objc_setAssociatedObject(self, @"refresh_header_key", refresh, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    
    [f addTarget:self
                                 action:@selector(refresh_envent)
                       forControlEvents:UIControlEventValueChanged];
    [f attachToScrollView:self];
    
    
}

- (void)refresh_envent{
    
     RefreshBlock block = objc_getAssociatedObject(self, @"refresh_header_key");
    
     block();
    
}


- (void)endHeaderFresh{
    
   YALSunnyRefreshControl *f = objc_getAssociatedObject(self, "YALSunnyRefreshControl");
    [f endRefreshing];
 
}


@end
